<template>
  <div class="result-page">
    <div class="ms_box">
      <h1 class="rt_tle">基础信息及五行分析</h1>
      <div class="result_box">
        <x-table class="name_des_1">
          <tbody>
            <tr class="tb_tle">
              <td style="width:20%">姓氏</td>
              <td style="width:20%">性别</td>
              <td>出生日期</td>
              <td style="width:20%">属</td>
            </tr>
            <tr>
              <td>{{result.surname}}</td>
              <td>{{result.sex | sexChange}}</td>
              <td>农历：{{result.yl}}</td>
              <td>{{ result.shu }}</td>
            </tr>
            <tr>
              <td>八字为</td>
              <td colspan="3">
                <span v-for="bzs in result.bz" class="tb_sp">
                  {{bzs}}
                </span>
              </td>
            </tr>
            <tr>
              <td>五行为</td>
              <td colspan="3">
                <span v-for="wxs in result.wx" class="tb_sp">
                  {{wxs}}
                </span>
              </td>
            </tr>
            <tr>
              <td>五行分析</td>
              <td colspan="3">{{ result.describe }}</td>
            </tr>
          </tbody>
        </x-table>

        <wx-leida ref="wx_ld" />
      </div>

      <h1 class="rt_tle">起名列表</h1>
      <div class="result_box" v-for="item in name_list">
        <x-table class="name_des_2">
          <tbody>
            <tr>
              <td colspan="4" class="bg_s2">
                <span class="fl_cen ft_bd fl_left">

                  <span class="name_word_bg">{{result.surname}}</span>
                  <span class="name_word_bg" v-for="name_s in item.name">{{name_s}}</span>
                  <!-- {{result.surname+item.name}} -->
                </span>
                <span class="fl_right score">
                  {{item.score}}
                  <span style="font-size:16pt">分</span>
                </span>
              </td>
            </tr>
            <tr>
              <td style="width:24%">五行分析</td>
              <td>
                <p>根据五行分析结果看，五行喜{{result.wx_xihao}}，{{ item.wx_word }}字的五行属性为{{result.wx_xihao}}</p>
              </td>
            </tr>
            <tr>
              <td style="width:24%">字义分析<br>（取自新华字典）</td>
              <td class="wx_mean">
                <span v-for="s in item.mean" v-html="s.mean">
                  <span v-if="s.mean !== ''">暂无解释~</span>
                </span>
              </td>
            </tr>
          </tbody>
        </x-table>
      </div>
    </div>
    <loading :show="loading_show" text="加载中..."></loading>
  </div>
</template>

<script>
import WxLeida from "../componments/echart/wx_leida.vue"
import { XTable, Loading } from "vux"
import g from "../common/js/http.js"
export default {
  components: {
    XTable,
    WxLeida,
    Loading
  },
  data() {
    return {
      result: "",
      wx_arr: "",
      name_list: "",
      loading_show: false
    }
  },
  created() {
    var req_data = {
      date_s: this.$route.query.date_s,
      time_s: this.$route.query.time_s,
      surname: this.$route.query.surname,
      sex: this.$route.query.sex,
      page: this.$route.query.page
    }
    this.getData(req_data)
  },
  filters: {
    sexChange(val) {
      if (val == "1") {
        return "男"
      } else {
        return "女"
      }
    },
    replace_str(val) {
      return val.replace("<br>", "")
    }
  },
  methods: {
    getData(req_data) {
      this.loading_show = true
      var _this = this
      g.post_func("/api/v1/bz_qm", req_data, function(data) {
        if (data.code == 200) {
          var data_arr = data.data
          _this.name_list = data_arr.name_arr.sort(_this.compare("score"))
          _this.result = data_arr
          _this.$refs.wx_ld.show_chart(_this.result.wx_arr)
          _this.replace_word()
        }else{
          alert('网络错误！请稍后重试')
          this.$router.push('/')
        }
        _this.loading_show = false
      })
    },
    compare(property) {
      return function(a, b) {
        var value1 = a[property]
        var value2 = b[property]
        return value2 - value1
      }
    },
    replace_word() {
      var _this = this
      this.result.name_arr.forEach(element => {
        element.mean.forEach(v => {
          v.mean.replace(v.hz, '<font style="color:red">' + v.hz + "</font>")
        })
      })
    }
  }
}
</script>
<style scoped>
.wx_mean {
  height: 200px;
  overflow-y: auto;
  display: block;
  text-align: left;
}
.tb_tle td {
  font-weight: 600;
}
.btn_detial {
  display: block;
  height: 32px;
  width: 100px;
  margin: 0 auto;
  line-height: 32px;
  color: #fff;
  background: #fbb03b;
  border: 2px solid #fbb03b;
  text-align: center;
  cursor: pointer;
  border-radius: 4px;
}
.fl_left {
  display: block;
  float: left;
}
.fl_right {
  display: block;
  float: right;
}
.ft_bd {
  font-weight: 600;
}
.fl_cen {
  line-height: 75pt;
  font-size: 16pt;
}
.name_word_bg {
  background-image: url("../../static/icon/bg_s3.png");
  background-size: 100%;
  padding: 10px;
  background-repeat: no-repeat;
}
.tb_sp {
  background: #eee;
  margin-left: 2.5px;
  color: #333;
  padding: 5px;
}
.result_box {
  border: 1px solid #2c2121;
  background-color: #fff;
  width: 95%;
  padding: 3px;
  margin: 20px auto;
}
.rt_tle {
  font-size: 14pt;
  font-weight: 600;
  border-left: 5px solid #e3434f;
  text-align: left;
  margin: 15px 0;
  padding-left: 5px;
}
.score {
  font-size: 30pt;
  color: red;
  line-height: 70pt;
}
.bg_s2 {
  background-image: url("../../static/icon/bg_s2.png");
  background-size: 100%;
}
</style>